home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 11
/
Cream of the Crop 11-1.iso
/
program
/
heatmon.zip
/
LP.C
next >
Wrap
C/C++ Source or Header
|
1995-12-09
|
16KB
|
649 lines
#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <bios.h>
#include "lp.h"
int key;
FILE *fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8;
struct tm *ptr;
time_t p_start;
char t_start[25],on_start[25],off_start[25];
char f_stat[4];
int fm_on=0,fm_off=0,fmcalc1=0,fmcalc2=0;
int fo_used=0,fo_rem=0,focalc1=0,focalc2=0;
char fo_alarm='n';
int fc_size=0;
int fc_preset=0;
int fpreset=0;
int on_hour=0,on_min=0,on_sec=0;
int off_hour=0,off_min=0,off_sec=0;
int calc_on=0,calc_off=0;
time_t lt;
float lfile_size=0;
char lfile_status='A';
float lfile_max=850000;
char alert_log='I',alert_fuel='I';
int times_on=0,times_off=0;
int x=0,y=0;
char alert_notify='A';
int oil_min=50;
/* Fuel est: 45 gals = 14days */
/* .0459 gal per hour */
/* .000765 gal per minute */
/* .0000128 gal per second */
float oil_gps=0.0000128;
float oil_rem=0,oil_used=0;
main()
{
unsigned status;
unsigned lpt_io();
unsigned int i;
p_start = time(NULL);
ptr = localtime(&p_start);
strcpy(t_start,asctime(ptr));
clrscr();
for(;;){
menu_loop();
}
}
menu_loop()
{
char ch;
char endkey;
clrscr();
gotoxy(1,1);
cprintf(" Home Heating System - ver: 1.00 \n");
gotoxy(1,2);
cprintf("*******************************************\n");
gotoxy(1,3);
cprintf(" MAIN MENU \n");
gotoxy(1,4);
cprintf("-------------------------------------------\n");
gotoxy(1,5);
cprintf("MODE Option Description \n");
gotoxy(1,6);
cprintf("------ ------ ----------------------------\n");
gotoxy(1,7);
cprintf("ONLINE 1 Start Monitoring System \n");
gotoxy(1,8);
cprintf("ONLINE 2 Dump Monitor Data \n");
gotoxy(1,9);
cprintf("ONLINE 3 Reset Monitor stats \n");
gotoxy(1,10);
cprintf("ONLINE 4 Disable all alarms! \n");
gotoxy(1,11);
cprintf("OFFLINE 5 Set Furn Status -> OFF \n");
gotoxy(1,12);
cprintf("OFFLINE 6 Reset Fuel Status (FILL) \n");
gotoxy(1,13);
cprintf("ONLINE 7 Toggle notify status alarm \n");
gotoxy(1,14);
cprintf("ONLINE 8 Recover statistics \n");
gotoxy(1,15);
cprintf("ONLINE 9 Set Current Gallons of Oil \n");
gotoxy(1,16);
cprintf("ONLINE X Exit/End Monitoring System \n");
gotoxy(1,18);
cprintf("==========>\n");
gotoxy(13,18);
getcode();
switch (key){
case 49:
clrscr();
strcpy(f_stat," ");
while(!bioskey(1)) furn_loop();
clrscr();
printf("Press Enter to Continue! \n");
getch();
break;
case 50:
clrscr();
printf("Processing Monitor data.\n");
printf("COPYING:Furndat====>Furnout\n");
fclose(fp1);
if((fp1=fopen("furndat","r")) == NULL){
printf("Cannot open data file \n\a");
getch();
}
if((fp2=fopen("A:furnout","wt")) == NULL){
printf("Cannot open output file \n\a");
getch();
}
while(!feof(fp1)){
ch = getc(fp1);
if(!feof(fp1))putc(ch,fp2);
}
printf("COPY COMPLETE\n");
lfile_size = 0;
lfile_status = 'A';
printf("closing files\n");
fclose(fp1);
fclose(fp2);
printf("erasing Furndat \n");
remove("furndat");
printf("Capture log stats --> reset\n");
alert_log='I';
printf("Processing is Complete!\n");
printf("Reopening Furndat data file \n");
if((fp1=fopen("Furndat","a")) == NULL){
printf("Cannot open Furndat file \n\a");
getch();
}
printf("Press Enter to continue\n\a\a\a");
getch();
break;
case 51:
clrscr();
printf("Resetting Monitor Stats\n");
printf("Logged on Minutes => RESET\n");
on_hour=0;
on_min=0;
on_sec=0;
printf("Logged off Minutes => RESET\n");
off_hour=0;
off_min=0;
off_sec=0;
printf("Initiate date/time => RESET\n");
printf("Fuel used => RESET\n");
printf("Fuel remaining => RESET\n");
printf("Furnace status => RESET\n");
times_on=0;
times_off=0;
printf("Processing Complete!\n");
printf("Press Enter to continue\n");
getch();
break;
case 52:
clrscr();
printf("Disabling all alarms!\n");
alert_log='I';
alert_fuel='I';
printf("complete\n");
printf("press Enter to continue\n");
getch();
break;
case 53:
clrscr();
printf("Setting Furnace status to =>OFF<=\n");
printf("press Enter to continue\n");
getch();
break;
case 54:
clrscr();
printf("Reset Fuel statistics - (OIL Fill up)\n");
oil_rem = 180;
oil_used = 0;
printf("Fuel Stats ==> RESET\n");
printf("Press Enter to continue\n");
getch();
break;
case 55:
clrscr();
printf("Toggle notify status alarm\n");
if(alert_notify == 'A'){
alert_notify='I';
}
if(alert_notify == 'I'){
alert_notify='A';
}
printf("Done.\n");
getch();
break;
case 56:
clrscr();
printf("Recover statistics from disk..\n");
printf("processing.. time on\n");
if((fp4=fopen("minon","rt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fscanf(fp4,"%i%i%i",&on_hour,&on_min,&on_sec);
fclose(fp4);
printf("processing.. time off\n");
if((fp6=fopen("minoff","rt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fscanf(fp6,"%i%i%i",&off_hour,&off_min,&off_sec);
fclose(fp6);
printf("processing.. # times on\n");
if((fp3=fopen("timeon","rt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fscanf(fp3,"%i",×_on);
fclose(fp3);
printf("processing.. # times off\n");
if((fp5=fopen("timeoff","rt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fscanf(fp5,"%i",×_off);
fclose(fp5);
printf("Done.\n");
getch();
break;
case 57:
clrscr();
printf("Please enter the current amount of \n");
printf("gallons in the oil tank. \n");
scanf("%f",&oil_rem);
printf("Done.");
getch();
break;
case 88:
clrscr();
printf("Exit Monitoring System \n");
printf("Are you sure?? y or n \n");
endkey=getche();
if(endkey=='y'){
exit(0);
}
else{
printf("\n");
printf("Exit aborted\n");
printf("Press enter to continue\n");
getch();
break;
}
case 120:
clrscr();
printf("Exit Monitoring System \n");
printf("Are you sure?? y or n \n");
endkey=getche();
if(endkey=='y'){
exit(0);
}
else{
printf("\n");
printf("Exit aborted\n");
printf("Press enter to continue\n");
getch();
break;
}
default:
clrscr();
printf("This key is not defined to the system??\n");
printf("Press enter to continue\n");
getch();
}
}
int getcode(void)
{
if(key=getch()){
return key;
}
else{
return(getch());
}
}
furn_loop()
{
unsigned status;
unsigned lpt_io();
unsigned int i;
char recid;
char p[]="*";
time_t lt,start_time, end_time;
gotoxy(15,1);
cprintf(" Home Heating Monitor - ver 1.00 \n");
gotoxy(15,2);
cprintf(" Program date: 11/28/95 \n");
gotoxy(15,3);
cprintf("-----------------------------------\n");
gotoxy(15,4);
printf("Initiated:");
printf("%s",t_start);
printf("\n");
gotoxy(15,5);
cprintf("Current heat status => %s \n",f_stat);
gotoxy(15,6);
cprintf("Logged on minutes => %4i:%2i:%2i \n",on_hour,on_min,on_sec);
gotoxy(15,7);
printf("On>%s",on_start);
gotoxy(15,8);
cprintf("Logged off minutes => %4i:%2i:%2i \n",off_hour,off_min,off_sec);
gotoxy(15,9);
cprintf("Off>%s",off_start);
gotoxy(15,10);
cprintf("Data Capture status => %c ",lfile_status);
gotoxy(15,11);
cprintf("Data File size => %f\n",lfile_size);
gotoxy(15,12);
cprintf("Abort capture at => %f\n",lfile_max);
gotoxy(15,13);
cprintf("Calculated fuel used=> %f\n",oil_used);
gotoxy(15,14);
cprintf("Calculated fuel rem => %f\n",oil_rem);
gotoxy(15,15);
cprintf("Preset alarm gals => %i\n",oil_min);
gotoxy(15,16);
fuel_graph();
gotoxy(15,17);
cprintf(" (Monitor status) \n");
gotoxy(15,18);
status = lpt_io(LPT1, 0, INIT);
cprintf(" Port => %u\n",status);
gotoxy(15,19);
cprintf("Times on=>%i Times off=>%i\n",times_on,times_off);
switch(status){
case 16:
lt=time(NULL);
gotoxy(15,20);
if(on_sec > 60){
on_min = on_min + 1;
on_sec = 0;
}
if(on_min > 60){
on_hour = on_hour + 1;
on_min = 0;
}
cprintf("FURNACE IS ON \n");
if(!stricmp(f_stat," ON")){
on_sec = on_sec + 1;
/* on time calc */
}
else{
on_sec = on_sec + 1;
if(on_sec > 60){
on_min = on_min + 1;
on_sec = 0;
}
if(on_min > 60){
on_hour = on_hour + 1;
on_min = 0;
}
if((fp3=fopen("timeon","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp3,"%i",times_on);
fclose(fp3);
if((fp4=fopen("minon","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp4,"%i%i%i",on_hour,on_min,on_sec);
fclose(fp4);
oil_used = oil_used + oil_gps;
oil_rem = oil_rem - oil_gps;
if((fp7=fopen("oiluse","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp7,"%f",oil_used);
fclose(fp7);
if((fp8=fopen("oilrem","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp8,"%f",oil_rem);
fclose(fp8);
if(on_sec > 60){
on_min = on_min + 1;
on_sec = 0;
}
if(on_min > 60){
on_hour = on_hour + 1;
on_min = 0;
}
if(alert_notify == 'A'){
printf("\a");
}
strcpy(f_stat," ON");
for(x=1;x<26;x++){
on_start[x]=' ';
}
strcpy(on_start,asctime(ptr));
times_on=times_on+1;
recid='A';
if(lfile_size > lfile_max){
lfile_status = 'I';
alert_log='A';
}
if(lfile_status=='A'){
if((fp1=fopen("furndat","a")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp1,"%c%s%i%i%i",recid,ctime(<),on_hour,on_min,on_sec);
lfile_size=lfile_size+27;
fclose(fp1);
}
}
if(on_sec > 60){
on_min = on_min + 1;
on_sec = 0;
}
if(on_min > 60){
on_hour = on_hour + 1;
on_min = 0;
}
biosprint(0,*p,1);
break;
default:
lt=time(NULL);
gotoxy(15,20);
if(off_sec > 60){
off_min = off_min + 1;
off_sec = 0;
}
if(off_min > 60){
off_hour = off_hour + 1;
off_min = 0;
}
cprintf("FURNACE IS OFF \n");
if(!stricmp(f_stat,"OFF")){
/* off calc */
off_sec = off_sec + 1;
}
else{
if(off_sec > 60){
off_min = off_min + 1;
off_sec = 0;
}
if(off_min > 60){
off_hour = off_hour + 1;
off_min = 0;
}
if((fp5=fopen("timeoff","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp5,"%i",times_off);
fclose(fp5);
if((fp6=fopen("minoff","wt")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp6,"%i%i%i",off_hour,off_min,off_sec);
fclose(fp6);
off_sec = off_sec + 1;
if(off_sec > 60){
off_min = off_min + 1;
off_sec = 0;
}
if(off_min > 60){
off_hour = off_hour + 1;
off_min = 0;
}
if(alert_notify=='A'){
printf("\a");
}
strcpy(f_stat,"OFF");
for(x=1;x<26;x++){
off_start[x]=' ';
}
strcpy(off_start,asctime(ptr));
times_off=times_off+1;
recid='I';
if(lfile_size > lfile_max){
lfile_status = 'I';
alert_log='A';
}
if(lfile_status=='A'){
if((fp1=fopen("furndat","a")) == NULL){
cprintf("Cannot open data file \n\a");
}
fprintf(fp1,"%c%s%i%i%i",recid,ctime(<),off_hour,off_min,off_sec);
lfile_size=lfile_size+27;
fclose(fp1);
}
}
if(off_sec > 60){
off_min = off_min + 1;
off_sec = 0;
}
if(off_min > 60){
off_hour = off_hour + 1;
off_min = 0;
}
break;
}
gotoxy(15,21);
cprintf("===================================\n");
sleep(1);
lt=time(NULL);
gotoxy(15,22);
cprintf(ctime(<));
gotoxy(15,23);
cprintf(" (Press any key to exit) \n");
}
alarms()
{
if(alert_log=='A'){
clrscr();
printf("DATA FILE: size has reached maximum!\n");
printf("Please Dump!! \a");
}
if(alert_fuel=='A'){
clrscr();
printf("<<<<<<<<<< FUEL DANGER >>>>>>>>>>>\n\a\a");
printf("FUEL is less than 50gal \a\a DANGER!!! \a\a \n");
}
}
fuel_graph()
{
if(oil_rem > 179){
cprintf(" EMPTY<****+*****|*****+****>FULL \n");
}
if(oil_rem < 179 && oil_rem > 175){
cprintf(" EMPTY<****+*****|*****+***->FULL \n");
}
if(oil_rem < 175 && oil_rem > 170){
cprintf(" EMPTY<****+*****|*****+**-->FULL \n");
}
if(oil_rem < 170 && oil_rem > 161){
cprintf(" EMPTY<****+*****|*****+*--->FULL \n");
}
if(oil_rem < 161 && oil_rem > 153){
cprintf(" EMPTY<****+*****|******---->FULL \n");
}
if(oil_rem < 153 && oil_rem > 144){
cprintf(" EMPTY<****+*****|*****+---->FULL \n");
}
if(oil_rem < 144 && oil_rem > 136){
cprintf(" EMPTY<****+*****|****-+---->FULL \n");
}
if(oil_rem < 136 && oil_rem > 127){
cprintf(" EMPTY<****+*****|***--+---->FULL \n");
}
if(oil_rem < 127 && oil_rem > 119){
cprintf(" EMPTY<****+*****|**---+---->FULL \n");
}
if(oil_rem < 119 && oil_rem > 110){
cprintf(" EMPTY<****+*****|*----+---->FULL \n");
}
if(oil_rem < 110 && oil_rem > 102){
cprintf(" EMPTY<****+******-----+---->FULL \n");
}
if(oil_rem < 102 && oil_rem > 93){
cprintf(" EMPTY<****+*****|-----+---->FULL \n");
}
if(oil_rem < 93 && oil_rem > 85){
cprintf(" EMPTY<****+****-|-----+---->FULL \n");
}
if(oil_rem < 85 && oil_rem > 76){
cprintf(" EMPTY<****+***--|-----+---->FULL \n");
}
if(oil_rem < 76 && oil_rem > 68){
cprintf(" EMPTY<****+**---|-----+---->FULL \n");
}
if(oil_rem < 68 && oil_rem > 59){
cprintf(" EMPTY<****+*----|-----+---->FULL \n");
}
if(oil_rem < 59 && oil_rem > 51){
cprintf(" EMPTY<*****-----|-----+---->FULL \n");
}
if(oil_rem < 51 && oil_rem > 42){
cprintf(" EMPTY<****+-----|-----+---->FULL \n");
alert_fuel = 'A';
}
if(oil_rem < 42 && oil_rem > 34){
cprintf(" EMPTY<***-+-----|-----+---->FULL \n");
alert_fuel = 'A';
}
if(oil_rem < 34 && oil_rem > 25){
cprintf(" EMPTY<**--+-----|-----+---->FULL \n");
alert_fuel = 'A';
}
if(oil_rem < 25 && oil_rem > 17){
cprintf(" EMPTY<*---+-----|-----+---->FULL \n");
alert_fuel = 'A';
}
if(oil_rem < 17){
cprintf(" EMPTY<----+-----|-----+---->FULL \n");
alert_fuel = 'A';
}
}
unsigned int
lpt_io(port,byte,mode)
unsigned port;
unsigned byte;
int mode;
{
unsigned i,j,status;
long unsigned otime;
switch (mode) {
case OUT:
outportb(port,byte);
outportb(port+2, 0x0d);
outportb(port+2, 0x0d);
outportb(port+2, 0x0c);
inportb(port+1);
status = (inportb(port+1) & 0x00f8) ^ 0x48;
return(status);
case IN:
return(inportb(port));
case IS_BUSY:
return ( (inportb(port+1) & 0x80) ^ 0x80 );
case IS_ACK:
return ( inportb(port+1) & 0x60 );
switch (byte) {
case ASSERT:
i = inportb(port+2);
outportb(port+2, i | 0x8);
return ( (inportb(port+1) & 0xf8) ^ 0x48 );
case DEASSERT:
i = inportb(port+2);
outportb(port+2, i & ~0x8);
return ( (inportb(port+1) & 0xf8) ^ 0x48 );
default:
return(~0);
}
case INIT:
otime = biostime(0,0L);
outport(port+2, 0x08);
while ( otime + 1 > biostime(0,0L)) ;
outportb(port+2, 0x0c);
case STAT:
return( ((inportb(port+1) & 0xf8) ^ 0x48) );
case IS_PRESENT:
outportb(port,0x55);
if (inportb(port) == 0x55) {
return(~0);
}
return(0);
default:
return(~0);
}
}